<template>
  <div class="member-order">

      <!-- <XtxTabs v-model="activeName" @tab-click="handleClick">
        <XtxTabsPanel label='11' name='44'>77</XtxTabsPanel>
        <XtxTabsPanel label='22' name='55'>88</XtxTabsPanel>
        <XtxTabsPanel label='33' name='66'>99</XtxTabsPanel>
      </XtxTabs> -->
      <XtxTabs v-model="activeName" @tab-click="handleClick">
        <XtxTabsPanel
         v-for="item in orderStatus"
         :key="item.name"
         :label='item.label'
         :name='item.name'
         ></XtxTabsPanel>
      </XtxTabs>

      <!-- 订单列表 -->
      <div class="order-list">
        <OrderItem v-for="item in list" :key="item.skuId" :order='item'/>
        <div class="etry" v-if="!list.length"> 空空如也...</div>
      </div>
  </div>
</template>
<script>
import { reactive, ref, watch } from 'vue'
import { orderStatus } from '@/constants/order'
import OrderItem from './components/order.item.vue'
import { reqFindOrderList } from '@/api/order'
export default {
  components: { OrderItem },
  name: 'MemberOrder',
  setup () {
    const activeName = ref('all')
    const handleClick = (val) => {
      // console.log(val)
      // 点击切换显示栏
      reqParams.orderState = val.index
    }
    // 需要传列表的参数
    const reqParams = reactive({
      // 订单状态，0为全部，1为待付款、2为待发货、3为待收货、4为待评价、5为已完成、6为已取消
      orderState: 0,
      page: 1,
      pageSize: 10
    })
    // 订单数组储存
    const list = ref([])
    watch(reqParams, () => {
      // 请求订单数据列表
      reqFindOrderList(reqParams).then(({ result }) => {
        // console.log(result)
        list.value = result.items
      })
      // immediate 立刻执行
    }, { immediate: true })

    return { handleClick, activeName, orderStatus, list }
  }
}
</script>
<style scoped lang="less">
.order-list {
  background: #fff;
  padding: 20px;
}
.etry{
  font-size: 22px;
  min-height: 500px;
  display: flex;
  justify-content: center;
  align-items: center;
}

</style>
